﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;

namespace FunCode.MVCweb.Controllers
{
    public class EFObjectContextModel
    {
        public string table { get; set; }
        public List<PropertyInfo> Properties { get; set; }

    }
    public class FunCodeController : Controller
    {
        //
        // GET: /FunCode/
        public ActionResult Index()
        {
            //获取bin目录下面的dll
            string BaseDirectory = AppDomain.CurrentDomain.BaseDirectory + "bin\\";
            return View(EFDriver.GetDllFileModels(BaseDirectory));
        }
        public ActionResult EFObjectContext(string ObjectContextName)
        {
            var noCovered = new string[] { "EntityState", "EntityKey" };
            List<EFObjectContextModel> modle = EFDriver.GetTables( ObjectContextName)
                .Select(table => new EFObjectContextModel
                {
                    table = table,
                    Properties = EFDriver.GetProperties(ObjectContextName, table, noCovered)
                })
                .ToList();
            ViewBag.ObjectContextName = ObjectContextName;
            return View(modle);
        }
        public ActionResult DwzCssListRenderBody(string ObjectContextName,string table)
        {
            var noCovered = new string[] { "EntityState", "EntityKey" };
            EFObjectContextModel Efocm = new EFObjectContextModel
                                             {
                                                 table = table,
                                                 Properties = EFDriver.GetProperties(ObjectContextName, table, noCovered)
                                             };
            return View(Efocm);
        }
    }
}
